package cn.tuling.config;

import cn.tuling.mybatis.MybatisFactoryBean;
import cn.tuling.mybatis.mapper.OrderMapper;
import cn.tuling.mybatis.mapper.UserMapper;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.stereotype.Component;

/**
 * 玩弄一下
 */
//@Component
public class MybatisBeanDefinitionRegistryPostProcessor implements BeanDefinitionRegistryPostProcessor {
    @Override
    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
        AbstractBeanDefinition userMapper = BeanDefinitionBuilder.genericBeanDefinition().getBeanDefinition();
        userMapper.setBeanClass(MybatisFactoryBean.class);
        userMapper.getConstructorArgumentValues().addGenericArgumentValue(UserMapper.class);
        registry.registerBeanDefinition("userMapper", userMapper);

        AbstractBeanDefinition orderMapper = BeanDefinitionBuilder.genericBeanDefinition().getBeanDefinition();
        orderMapper.setBeanClass(MybatisFactoryBean.class);
        orderMapper.getConstructorArgumentValues().addGenericArgumentValue(OrderMapper.class);
        registry.registerBeanDefinition("orderMapper", orderMapper);
    }

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {

    }
}
